package com.jubaozan.framework.sentinel.springmvc.listener;

import com.alibaba.csp.sentinel.property.SimplePropertyListener;
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRuleManager;
import com.jubaozan.framework.sentinel.constant.RuleKeyConstant;
import com.jubaozan.framework.sentinel.listener.RedisRulePublisher;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author jiangjinwu
 * @version 1.0
 * @since 2025/7/15 13:52
 */

@Slf4j
@Component
public class ParamPropertyListener extends SimplePropertyListener<List<ParamFlowRule>> {

    @Autowired
    RedisRulePublisher redisRulePublisher;
    @Autowired
    RuleKeyConstant ruleKeyConstant;

    ParamPropertyListener() {
    }

    public synchronized void configUpdate(List<ParamFlowRule> rules) {
        redisRulePublisher.pushRules(rules, ruleKeyConstant.getParamFlowRuleKey());
    }


    public synchronized void configLoad(List<ParamFlowRule> conf) {
        ParamFlowRuleManager.loadRules(conf);
        log.info("接收到热点规则加载: {}", conf);
    }
}
